package leetcode.code2105;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int minimumRefill(int[] plants, int capacityA, int capacityB) {
		int len = plants.length;
		int ans = 0;
		int l = 0, r = len - 1;
		int a = capacityA, b = capacityB;
		while (l <= r) {
			if (l == r) {
				int c = 0;
				if (a == b) {
					c = a;
				} else {
					c = Math.max(a, b);
				}
				if (c < plants[l]) {
					ans++;
				}
			} else {
				if (a >= plants[l]) {
					a -= plants[l];
				} else {
					a = capacityA - plants[l];
					ans++;
				}
				if (b >= plants[r]) {
					b -= plants[r];
				} else {
					b = capacityB - plants[r];
					ans++;
				}
			}
			l++;
			r--;
		}
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
